#!/bin/bash

# 设置变量
IMAGE_NAME="your-image-name"
IMAGE_TAG="latest"
DOCKERFILE_PATH="./Dockerfile"
BUILD_CONTEXT="./"

# 构建 Docker 镜像

docker build -t $IMAGE_NAME:$IMAGE_TAG -f $DOCKERFILE_PATH $BUILD_CONTEXT

# 推送镜像到镜像仓库（可选）
# docker login your-registry-url -u your-username -p your-password
# docker tag $IMAGE_NAME:$IMAGE_TAG your-registry-url/$IMAGE_NAME:$IMAGE_TAG
# docker push your-registry-url/$IMAGE_NAME:$IMAGE_TAG

# 输出构建完成信息
echo "Docker image $IMAGE_NAME:$IMAGE_TAG built successfully."

#停止之前的容器
docker stop your-container-name
#启动新的容器
docker run -d --name your-container-name -p 8080:8080 $IMAGE_NAME:$IMAGE_TAG